<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <meta name="browsermode" content="application">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="Cache" content="no-cache">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
    <!-- 禁止百度转码 -->
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <!-- uc强制竖屏 -->
    <meta name="screen-orientation" content="portrait">
    <!-- QQ强制竖屏 -->
    <meta name="x5-orientation" content="portrait">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta name="format-detection" content="telephone=no">
    <title>申请成为合伙人</title>
    <link rel="stylesheet" href="${request.contextPath}/web/css/reset.css?v=${verison!}">
    <link rel="stylesheet" href="${request.contextPath}/web/css/base.css?v=${verison!}">
    <link rel="stylesheet" href="${request.contextPath}/web/css/partner-apply.css?v=${verison!}">
    <link rel="stylesheet" href="${request.contextPath}/web/css/ydui.css">
    <link rel="stylesheet" href="${request.contextPath}/plug/layui/css/layui.css" media="all">
</head>
<body style="background-color: rgb(245, 245, 245);">
<div data-role="page">
    <div class="app">
        <div class="partnerApply absolute router">
            <div class="list">
                <div class="item acea-row row-between-wrapper">
                    <div class="name">姓&nbsp; &nbsp; &nbsp; &nbsp;名</div>
                    <input type="text" placeholder="请输入姓名" required="required" id="name">
                </div>
                <div class="item acea-row row-between-wrapper">
                    <div class="name">联系方式</div>
                    <input type="text" placeholder="请输入联系方式" required="required" id="phone">
                </div>
                <div class="item acea-row row-between-wrapper">
                    <div class="name">地&nbsp; &nbsp; &nbsp; &nbsp;址</div>
                    <input type="text" placeholder="请输入地址" required="required" id="address">
                </div>
                <div class="item acea-row row-between-wrapper">
                    <div class="name">身份证号码</div>
                    <input type="text" placeholder="身份证号码" required="required" id="sfzh">
                </div>
                <!-- <div class="item acea-row row-between-wrapper">
                     <div class="upload-name">个人身份证</div>
                     <div class="upload-credentials">
                         <img src="${request.contextPath}/web/images/upload-default.png" alt=""/>
                         <input type="hidden" class="file1">
                         <form method="post" enctype="multipart/form-data" action="" class="g-core-image-upload-form">
                             <input name="file" type="file" accept="image/*" onchange="fileChange(this,'file1')" id="file1">
                         </form>
                     </div>
                     <div class="upload-credentials">
                         <img src="${request.contextPath}/web/images/upload-default2.png" alt=""/>
                         <input type="hidden" class="file2">
                         <form method="post" enctype="multipart/form-data" action="" class="g-core-image-upload-form">
                             <input name="file" type="file" accept="image/*" onchange="fileChange(this,'file2')" id="file2">
                         </form>
                     </div>
                 </div>-->
            </div>
            <a class="keepBnt bg-color-red" onclick="buyPartner(1)">支付599元成为合伙人</a>
            <a class="keepBnt bg-color-black"  onclick="buyPartner(2)">购买商品成为合伙人</a>
        </div>
    </div>
    <#include "include/right.html" />
</div>
</body>
<script type="text/javascript" src="${request.contextPath}/web/js/media_750.js"></script>
<script type="text/javascript" src="${request.contextPath}/web/js/jquery.min.js"></script>
<script type="text/javascript" src="${request.contextPath}/web/js/jquery.mobile.min.js"></script>
<script type="text/javascript" src="${request.contextPath}/web/js/ydui.js"></script>
<script type="text/javascript" src="${request.contextPath}/web/js/common.js"></script>
<script src="${request.contextPath}/js/layer.js"></script>
<script src="${request.contextPath}/js/ajaxfileupload.js"></script>
<script>
    function fileChange(obj,fileId){
        var reader=new FileReader();
        var file=obj.files[0];
        reader.readAsDataURL(file);
        reader.onload=function(){
            $(obj).parent().parent().find("img").attr("src",reader.result);
            $.ajaxFileUpload({
		        url:"${request.contextPath}/web/upload",
		        secureuri:false,                           //是否启用安全提交,默认为false
		        fileElementId:fileId,               //文件选择框的id属性
		        dataType:'JSON',                           //服务器返回的格式,可以是json或xml(需要大写)等     text
		        success:function(data, status){            //服务器响应成功时的处理函数
		            console.log(data);
		            data = data.replace(/<pre.*?>/g, ''); // ajaxFileUpload会对服务器响应回来的text内容加上
		            data = data.replace("</pre>", ''); // 本例中设定上传文件完毕后,服务端会返回给前台[0`filepath]
		            data = eval("("+data+")");
		             console.log(data.data);
		            if (data.code == 200) {
                        $("."+fileId).val(data.data);
                         layer.msg("图片上传完成")
		            }else{
                        layer.msg(data.msg)
		            }
		        },
		        error:function(data, status, e){ //服务器响应失败时的处理函数
		           layer.msg("上传失败")
		        }
		     });
        }
    }
    function buyPartner(type){
        var obj = new Object();
        obj["name"] = $.trim($("#name").val());
        obj["phone"] =  $.trim($("#phone").val());
        obj["address"] =  $.trim($("#address").val());
        obj["type"] =  2;
        obj["sfzh"] = $.trim($("#sfzh").val());
        obj["sfzhImage1"] = $.trim($(".file1").val());
        obj["sfzhImage2"] = $.trim($(".file2").val());
        if("" == obj["name"]){
            layer.msg("姓名不能为空！")
            return;
        }
        if("" == obj["phone"]){
            layer.msg("联系方式不能为空！")
            return;
        }
        if(!isPhoneNo(obj["phone"])){
            layer.msg("联系方式不正确！")
            return;
        }
        if("" == obj["address"]){
            layer.msg("地址不能为空！")
            return;
        }
        if("" == obj["sfzh"]){
            layer.msg("身份证号不能为空！")
            return;
        }
        $.ajax({
              type: 'POST',
              url: '${request.contextPath}/web/applyInfo/add',
              data: JSON.stringify(obj),
              dataType:'json',
              contentType:'application/json',
              success: function(data){
                  if(data.code==200){
                     if(type == 1){
                        window.location.href="${request.contextPath}/weixin/unifiedOrder/"+data.data;
                     }else{
                        window.location.href="${request.contextPath}/web/searchResult?isBepartner=1";
                     }
                  }else{
                     layer.msg(data.msg)
                  }
              }
        });
    }
</script>
</html>